import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

//创建并暴露store
export default new Vuex.Store({
  //状态
  state: {
    sum: 0,
    name:'张三',
    age:18
  },
  //改变
  mutations: {
    Add(state, value) {
      console.log(state, value);
      state.sum += value
    },
    Delete(state,value){
      state.sum -= value
    }
  },
  //行动
  actions: {
    add(context, value) {
      console.log(context, value)
      context.commit('Add', value)
    },
    delete(context,value){
      context.commit('Delete',value)
    }
  },
  //用于将state中的数据进行加工,页面中拿该数据：this.$store.getters.bigSum
  getters:{
    bigSum(state){
      return state.sum*10
    }
  },
  modules: {}
})